package com.exchange.logger.impl;

import com.exchange.dto.LoggerDto;
import com.exchange.logger.LoggerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

/***
 *                    .::::.
 *                  .::::::::.
 *                 :::::::::::
 *             ..:::::::::::'
 *           '::::::::::::'
 *             .::::::::::
 *        '::::::::::::::..
 *             ..::::::::::::.
 *           ``::::::::::::::::
 *            ::::``:::::::::'        .:::.
 *           ::::'   ':::::'       .::::::::.
 *         .::::'      ::::     .:::::::'::::.
 *        .:::'       :::::  .:::::::::' ':::::.
 *       .::'        :::::.:::::::::'      ':::::.
 *      .::'         ::::::::::::::'         ``::::.
 *  ...:::           ::::::::::::'              ``::.
 * ```` ':.          ':::::::::'                  ::::..
 *                    '.:::::'                    ':'````..
 *
 * @Author liuhai
 * @Date 2020-10-04 15:33:45
 * @Description
 */
@Service("LoggerService")
public class LoggerServiceImpl implements LoggerService {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void addMgLogger(LoggerDto loggerDto) {
        mongoTemplate.save(loggerDto);
    }

    @Override
    public List<LoggerDto> queryLogger(int offset, int limit){
        Query query = new Query();
        //分页查询
        query.skip(offset).limit(limit);
        //条件查询1，多条件is("值")后面可以加and("字段2").is("值2")
        query.addCriteria(Criteria.where("logType").is("2"));
        //条件查询2，gte大于 lte小于
        //query.addCriteria(Criteria.where("timestamp").gte(startTime).lte(endTime+1000));
        return mongoTemplate.find(query, LoggerDto.class);
    }
}
